function eraseOverlapIntervals(intervals: number[][]): number {
    if (intervals.length === 0) return 0;
    intervals.sort((a, b) => a[0] - b[0]);
    let right: number = intervals[0][1];
    let tempInterval: number[];
    let resCount: number = 0;
    for (let i = 1, length = intervals.length; i < length; i++) {
        tempInterval = intervals[i];
        if (tempInterval[0] >= right) {
            // 未重叠
            right = tempInterval[1];
        } else {
            // 有重叠，移除当前interval和前一个interval中右边界更大的那个
            right = Math.min(right, tempInterval[1]);
            resCount++;
        }
    }
    return resCount;
};
